@extends('admin::layouts.master')
@section('content')
    <div class="col-lg-12">
        <div class="card card-table">
            <div class="card-header">分类管理
                <button class="btn btn-primary ml-2">分类列表</button>
                <button class="btn btn-primary" data-toggle="modal" data-target="#add">添加分类</button>
                @component('components.modal',['title' => '添加分类','url' => '/shop/category','name'=>'add'])
                    <div class="form-group">
                        <label>分类名称</label>
                        <input type="text" required placeholder="请输入分类名称..." name="cname" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>所属分类</label>
                        <div class="">
                            <select name="pid" class="form-control">
                                <option value="0" selected="">顶级分类</option>
                                @foreach(\Modules\Shop\Entities\Category::getCategory () as $cate)
                                <option value="{{$cate['id']}}">{!! $cate['cname'] !!}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                @endcomponent
            </div>
            <div class="card-body">
                <table class="table">
                    <thead>
                    <tr>
                        <th>分类ID</th>
                        <th>分类名称</th>
                        {{--<th>所属分类</th>--}}
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($cates as $cate)
                    <tr>
                        <td>{{$cate['id']}}</td>
                        <td>{!! $cate['_cname'] !!}</td>
                        {{--@if(isset($cate->fenlei->cname))--}}
                        {{--<td>{{$cate->fenlei->cname}}</td>--}}
                        {{--@else--}}
                        {{--<td>顶级分类</td>--}}
                        {{--@endif--}}
                        <td>{{$cate['created_at']}}</td>
                        <td>
                            <div class="btn-group" role="group" aria-label="Basic example">
                                <button data-toggle="modal" data-target="#cateedit{{$cate['id']}}" type="button" class="btn btn-success">编辑</button>
                                @component('components.modal',['title' => '编辑用户','url' => '/shop/category/'.$cate['id'],'name'=>'cateedit'.$cate['id'],'id'=>$cate['id'],'method'=>'PATCH'])
                                    <div class="form-group">
                                        <label>分类名称</label>
                                        <input type="text"  value="{{$cate['cname']}}" name="cname" class="form-control">
                                    </div>
                                    <div class="form-group">
                                        <label>所属分类</label>
                                        <div class="">
                                            <select class="form-control" name="pid">
                                                @if($cate['pid']==0)
                                                    <option selected value="0">顶级分类</option>
                                                @else
                                                    <option value="0">顶级分类</option>
                                                @endif
                                                @foreach(\Modules\Shop\Entities\Category::getCategory ($cate) as $cate1)
                                                        <option {{$cate1['_disabled']?'disabled':''}} value="{{$cate1['id']}}" {{$cate1['_selected']?'selected':''}}>{!! $cate1['_cname'] !!}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                @endcomponent
                                <form action="{{route('category.destroy',$cate['id'])}}" method="post">
                                    @csrf
                                    @method('DELETE')
                                <button type="submit" class="btn btn-danger">删除</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @endforeach
                    </tbody>
                </table>

            </div>

        </div>
    </div>
@endsection
